home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 May / SGI IRIX 6.5 Applications 1999 May.iso / dist / impr_base.idb / usr / sbin / mkbsdpr.z / mkbsdpr
Text File  |  1998-05-04  |  6KB  |  200 lines

  1. #! /bin/sh
  2. #Tag 0x00000700
  3. #**************************************************************************
  4. #*
  5. #*           Copyright (c) 1992 Silicon Graphics, Inc.
  6. #*            All Rights Reserved
  7. #*
  8. #*       THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
  9. #*
  10. #* The copyright notice above does not evidence any actual of intended
  11. #* publication of such source code, and is an unpublished work by Silicon
  12. #* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
  13. #* the property of Silicon Graphics, Inc. Any use, duplication or
  14. #* disclosure not specifically authorized by Silicon Graphics is strictly
  15. #* prohibited.
  16. #*
  17. #* RESTRICTED RIGHTS LEGEND:
  18. #*
  19. #* Use, duplication or disclosure by the Government is subject to
  20. #* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
  21. #* Technical Data and Computer Software clause at DFARS 52.227-7013,
  22. #* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
  23. #* Supplement. Unpublished - rights reserved under the Copyright Laws of
  24. #* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
  25. #* Shoreline Blvd., Mountain View, CA 94039-7311
  26. #**************************************************************************
  27. #*
  28. #* File: mkBSDpr
  29. #*
  30. #* $Revision: 1.11 $
  31. #*
  32. #* Description: A script to install a System V printer that forwards
  33. #*    print jobs to a BSD printer. The BSD printer must already be
  34. #*    installed on the system before this script is executed.
  35. #*
  36. #*    Usage: mkBSDpr lp_printer_name bsd_printer_name
  37. #*
  38. #*    Where lp_printer_name is the local name you want to assign the
  39. #*    system V printer and bsd_printer_name is the lcoal name of the
  40. #*    BSD printer to which jobs should be forwarded.
  41. #*
  42. #**************************************************************************
  43.  
  44. usage() {
  45.     echo "usage: mkBSDpr [-v] [-l] lp_printer_name bsd_printer_name"
  46.     echo "-h            Display the usage message"
  47.     echo "-v            Keep a verbose activity log"
  48.     echo "-l            Make a unique log file for the printer"
  49.     echo "lp_printer_name        System V local printer name"
  50.     echo "bsd_printer_name         BSD local printer name"
  51.     }
  52.  
  53. if [ ! -r /var/spool/lp/model/bsdface ]; then
  54.     echo ""
  55.     echo "ERROR: Before using this unsupported gift program,"
  56.     echo "       you must manually copy the model file 'bsdface'"
  57.     echo "       from the Impressario gifts directory."
  58.     echo ""
  59.         echo " Please be aware that this is an unsupported gift,"
  60.     echo " provided for your convenience, but not tested or supported"
  61.     echo " by Silicon Graphics."
  62.     echo ""
  63.     echo " Now that you've heard the disclaimer, type this to continue:"
  64.     echo ""
  65.     echo " su"
  66.     echo " cp /usr/impressario/gifts/models/bsdface /var/spool/lp/model"
  67.     echo " mkbsdpr $*"
  68.     echo ""
  69.     exit 1;
  70. fi
  71.  
  72. cid=`/usr/bin/id | /usr/bin/nawk '{print substr($1,index($1,"("))}'`;
  73. if [ "$cid" != "(root)" ]; then
  74.         echo "You must be logged in as root to use this program."
  75.         exit 1;
  76. fi
  77. if [ ! -r /var/spool/lp ]; then
  78.         echo "The System V spooling system is not installed on this system."
  79.         exit 1
  80. fi
  81.  
  82.  
  83. # Check to see if lpr is installed on this machine. Printcap is the heart
  84. # of BSD spooler, check if it exists.
  85. if [ ! -f /etc/printcap ]
  86. then
  87.     echo "The BSD spooling system is not installed on this machine."
  88.     exit 1
  89. fi
  90.  
  91. while getopts vl flag
  92. do
  93.     case $flag in
  94.         v)
  95.             # Turn on verbose flag in printer driver.
  96.             # This turns the verbose flag on by default in the
  97.             # printer driver.  The verbose flag may be controlled
  98.             # in each print job by use of the -overb/-onoverb
  99.             # options to the lp command.
  100.             VFLAG="VERBOSE=1"
  101.             ;;
  102.         l)
  103.             # Use a separate log file.
  104.             SPECIALLOG=1
  105.             ;;
  106.         \? | h)
  107.             usage
  108.             exit 1
  109.             ;;
  110.     esac
  111. done
  112.  
  113. shift `expr $OPTIND - 1`
  114.  
  115. if [ $# != 2 ] ; then
  116.     echo "$0: Insufficient number of arguments"
  117.     usage
  118.     exit 1
  119. fi
  120.  
  121. LP_PRINTER=$1
  122. HOSTNAME=`hostname`
  123. BSD_PRINTER=$2
  124. BSD_DUMMY_DEV=/var/spool/lp/bsd_printer
  125. BSD_INTERFACE=bsdface
  126.  
  127. # The standard place to have sd (spool dir) is /var/spool/<printer_name>.
  128.  
  129. # Test whether another SVR3 printer is installed under that name:
  130. if [ -s /var/spool/lp/member/$LP_PRINTER ]; then
  131.     echo "ERROR: An 'lp' printer called '$LP_PRINTER' is already installed."
  132.     echo "       Please choose another name and try again."
  133.     echo "       (Type 'lpstat -a' for a list of installed printers.)"
  134.     exit 1;
  135. fi
  136.  
  137. # Let's make sure that printer is configured in BSD spooling system.
  138. MatchingPrinters=`/usr/bin/grep $BSD_PRINTER /etc/printcap`
  139. if [ -z "$MatchingPrinters" ]; then
  140.         echo "ERROR: No printer named '$BSD_PRINTER' appear in /etc/printcap."
  141.     echo "       You must first install and verify the BSD lpr printer"
  142.     echo "       before you can install an SVR3 lp printer queue."
  143.         exit 1;
  144. fi
  145.  
  146. # Make a unique log file for this printer in /var/spool/lp/etc/log
  147. # if requested with the -l option.  The default is to use the communal
  148. # log file /var/spool/lp/log.
  149.  
  150. if [ "$SPECIALLOG" != "" ]
  151. then
  152.     PDIR=/var/spool/lp/etc/log
  153.     if test ! -d $PDIR ; then
  154.         mkdir $PDIR
  155.     fi
  156.  
  157.     LOGFILE=${PDIR}/${LP_PRINTER}-log
  158.     rm -rf ${LOGFILE}*
  159.  
  160.     cp /dev/null ${LOGFILE}
  161.     chown lp $PDIR ${LOGFILE}
  162.     chgrp bin $PDIR ${LOGFILE}
  163.     chmod 664 ${LOGFILE}
  164.     chmod 775 $PDIR
  165.     LFLAG="LOGFILE=$LOGFILE"
  166.     echo "Log file for printer \"$PRINTER\" will be $LOGFILE"
  167. fi
  168.  
  169. # Let us create a dummy device file so that lobpod will not think it
  170. # is a printer configured on the remote system.
  171. #
  172. if [ ! -r $BSD_DUMMY_DEV ]
  173. then
  174.     dev_info=`/bin/ls -l /dev/null`
  175.     major_dev=`echo $dev_info|/usr/bin/awk \
  176.                 '{print substr($5,$5,index($5,",")-1)}'`
  177.     minor_dev=`echo $dev_info|/usr/bin/awk '{print $6}'`
  178.     /etc/mknod $BSD_DUMMY_DEV c $major_dev $minor_dev
  179.     chmod 664 $BSD_DUMMY_DEV
  180.     chown lp.sys $BSD_DUMMY_DEV
  181. fi
  182.  
  183. if /usr/lib/lputil add $BSD_DUMMY_DEV $BSD_INTERFACE "$LP_PRINTER" \
  184.                     HOSTNAME=$HOSTNAME \
  185.                     HOSTPRINTER=$BSD_PRINTER \
  186.                     $VFLAG \
  187.                     $LFLAG
  188. then
  189.     # report what we have done
  190.     echo ""
  191.     echo "Printer '$LP_PRINTER' installed."
  192.     echo ""
  193.     echo "This is your current printing environment:"
  194.     lpstat -t | more
  195.     exit 0
  196. else
  197.     echo "ERROR: Failed to add new printer."
  198.     exit 1
  199. fi
  200.